

	cd "/Users/emanuelcoman/Dropbox/My Mac (Emanuel’s MacBook Air)/Documents/national_vote/revisions_cps/cps_reproduce/"


											*****Table 3*****
	use "data_torun_FINAL6.dta", clear
	
	
										
tab loc_year, gen(year_)
		drop year_1 /*the first one stays out of the regression*/
		tab country, gen(country_dummy)
		drop country_dummy1 /*the first one stays out of the regression*/
		rdrobust gov_party_loc rdd_score, vce (nncluster loc_ID) covs(year_* country_dummy*) level(95)
		
		*Conventional |  .00169     .00953   0.1772   0.859   -.016985      .020362
		
		rdrobust seat_majority_lag rdd_score, vce (nncluster loc_ID) covs(year_* country_dummy*) level(95)

		
											****Figure 1*******
	use "data_torun_FINAL6.dta", clear

	rddensity rdd_score 
	
capture preserve
*

capture drop temp_*
qui rddensity rdd_score, plot plot_range(-50 50) hist_range(-50 50) genvars(temp)

local ci_plot_region_l = `"(rarea temp_cil temp_cir temp_grid if temp_group == 0, sort lcolor(white%0) color(red%30))"'
local ci_plot_region_r = `"(rarea temp_cil temp_cir temp_grid if temp_group == 1, sort lcolor(white%0) color(blue%30))"'

local es_plot_line_l = `"(line temp_f temp_grid if temp_group == 0, sort lcolor(red) lwidth("medthin") lpattern(solid))"'
local es_plot_line_r = `"(line temp_f temp_grid if temp_group == 1, sort lcolor(blue) lwidth("medthin") lpattern(solid))"'

qui su temp_hist_width if temp_hist_group == 0
local hist_width_l = r(mean)
qui su temp_hist_width if temp_hist_group == 1
local hist_width_r = r(mean)

local plot_histogram_l = `"(bar temp_hist_height temp_hist_center if temp_hist_group == 0, barwidth(`hist_width_l') color(red%20))"'
local plot_histogram_r = `"(bar temp_hist_height temp_hist_center if temp_hist_group == 1, barwidth(`hist_width_r') color(blue%20))"'

local graph_opt = `"xline(0, lcolor(black) lwidth(medthin) lpattern(solid)) graphregion(color(white)) ylab(,nogrid) legend(off) title("`i'", color(gs0)) xtitle("Local majority closeness") ytitle("")"'

twoway 	`plot_histogram_l' 	/// 
				`plot_histogram_r' 	/// 
				`ci_plot_region_l' 	///
				`ci_plot_line_l'   	///
				`ci_plot_ebar_l'   	///
				`ci_plot_region_r' 	///
				`ci_plot_line_r'   	///
				`ci_plot_ebar_r'   	///
				`es_plot_line_l' 	///
				`es_plot_point_l' 	///
				`es_plot_line_r' 	///
				`es_plot_point_r' 	///
				,					///
				`graph_opt'

graph export "figure1.pdf", replace


											******Figure 2*******
		
	use "data_torun_FINAL6.dta", clear

global y nat_perc
global x rdd_score
global c 0
su $x
global x_min = r(min)
global x_max = r(max)

rdplot $y $x, genvars hide ci(95)

twoway (scatter rdplot_mean_y rdplot_mean_bin, sort msize(tiny)  mcolor(gs10)) ///
(line rdplot_hat_y $x if $x<0, lcolor(black) sort lwidth(medthin) lpattern(solid)) ///
(line rdplot_hat_y $x if $x>=0, lcolor(black) sort lwidth(medthin) lpattern(solid)), ///
xline($c, lcolor(black) lwidth(medthin)) xscale(r($x_min $x_max))  /// 
legend(off) graphregion(color(white)) ylab(,nogrid) ytitle("National vote percent") xtitle("Local majority index") 

graph export "figure2.pdf", replace


	
											******Figure 3*******
											
	
				
local DV nat_perc nat_perc10 

foreach x of local DV{
use "data_torun_FINAL6.dta", clear
 ***gen year dummies that are unique for each country
		tab nat_year, gen(year_`x')
		drop year_`x'1 /*the first one stays out of the regression*/
		tab country, gen(country_`x')
		drop country_`x'1 /*the first one stays out of the regression*/

		cls
		rdrobust `x' rdd_score if rdd_score<=50&rdd_score>=-50, vce (nncluster loc_ID) covs(year_`x'* country_`x'*) level(95)
		
		translate @Results "figure3_`x'.txt", replace


}

		

***Bring in the txt results from thre regression
	local DV nat_perc nat_perc10

foreach x of local DV{
import delimited "figure3_`x'.txt", delimiters("\t") clear

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)




split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}

capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data22+data23

capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data22
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1

gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="Continuity"
gen DV="`x'"


save "figure3`x'.dta", replace
}


****merge them
use "figure3nat_perc.dta", clear
save "FINAL_figure3.dta", replace

		
local DV nat_perc nat_perc10

foreach x of local DV{
use "FINAL_figure3.dta", clear
merge m:m DV sample using "figure3`x'.dta"
drop _merge
save "FINAL_figure3.dta", replace

}

***Graph the results

tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right

mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc", mat(Continuity)

 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 =".")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) ///
		graphregion(color(white)) ylab(,nogrid) ysize(1.5) xsize(2) legend(off) ///
		xscale(range(-.5 2)) xmtick(-.5(.5)2) xlabel(-.5(.5)2) ///
		fxsize(100) title("Percent") saving(fig3_cont_nat_perc, replace)
		
		keep if DV=="nat_perc10"
mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc10", mat(Continuity)

 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 =" .")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) ///
		graphregion(color(white)) ylab(,nogrid) ysize(1.5) xsize(2) legend(off) ///
		xscale(range(-1 8)) xmtick(-1(2)8) xlabel(-1(2)8) ///
		fxsize(100) title("Percent adjusted") saving(fig3_cont_nat_perc10, replace)
		
		
		 grc1leg fig3_cont_nat_perc.gph fig3_cont_nat_perc10.gph, cols(2) graphregion(color(white)) saving(fig3_cont_combined, replace)

		 graph export "figure3.pdf", replace
  

											*****Figure 4******
								
		
local country Italy Austria Czechia France Germany Portugal Romania Spain ///
			Belgium Bulgaria Denmark Finland Latvia Lithuania Luxembourg
				
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local country{
 			use "data_torun_FINAL6.dta", clear

		***gen year dummies that are unique for each country
		tab nat_year if country=="`x'", gen(year_`x')
		drop year_`x'1 /*the first one stays out of the regression*/
		drop if rdd_score==0
		cls
		rdrobust `j' rdd_score if country=="`x'", vce (nncluster loc_ID) covs(year_`x'*) level(95)
		
		translate @Results "figure4`j'_`x'.txt", replace

}
}


local country Austria Czechia France Germany Italy Portugal Romania Spain ///
				Belgium Bulgaria Denmark Finland Latvia Lithuania Luxembourg
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local country{
import delimited "figure4`j'_`x'.txt", delimiters("\t") clear

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)




split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}


capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19
			
		
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1

gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="Continuity"
gen country="`x'"
gen DV="`j'"


save "figure4`j'_`x'.dta", replace
}
}

****merge them
use "figure4nat_perc_Austria.dta", clear
save "FINAL_figure4.dta", replace

		
local country Austria Czechia France Germany Italy Portugal Romania Spain ///
				Belgium Bulgaria Denmark Finland Latvia Lithuania Luxembourg
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local country{
use "FINAL_figure4.dta", clear
merge m:m DV country sample using "figure4`j'_`x'.dta"
drop _merge
save "FINAL_figure4.dta", replace

}
}

**Graph the results

use "FINAL_figure4.dta", clear
		
		***keeep only a few countries
		keep if country=="Austria"|country=="Czechia"|country=="France"|country=="Germany"| ///
					country=="Italy"|country=="Portugal"|country=="Romania"|country=="Spain"


sort DV country sample

tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right

mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Austria" r2="Czechia" r3="France" r4="Germany" r5="Italy" r6="Portugal" r7="Romania" r8="Spain")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(cont_nat_perc, replace)						
						
						keep if DV=="nat_perc10"
mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc10", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Austria" r2="Czechia" r3="France" r4="Germany" r5="Italy" r6="Portugal" r7="Romania" r8="Spain")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(cont_nat_perc10, replace)
						
					 grc1leg cont_nat_perc.gph cont_nat_perc10.gph, cols(2) graphregion(color(white)) saving(cont_by_country, replace)
				 graph export "figure4.pdf", replace
				 
				 
										*****Figure 5*****
										
	
local party_size 1 2 3
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local party_size{
	use "data_torun_FINAL6.dta", clear
	*gen a variable denoting national party size below sd, above sd and in between
by country nat_year, sort: egen nat_sd=sd(nat_perc)
by country nat_year, sort: egen nat_average=mean(nat_perc)

gen one_sd_below=nat_average-nat_sd
gen one_sd_above=nat_average+nat_sd

gen above_below_sd=.
replace above_below_sd=1 if nat_perc<one_sd_below
replace above_below_sd=2 if nat_perc>one_sd_below&avg_nat_perc<one_sd_above
replace above_below_sd=3 if nat_perc>one_sd_above
		***gen year dummies that are unique for each country
		tab nat_year if above_below_sd==`x', gen(year_`x'_)
		drop year_`x'_1 /*the first one stays out of the regression*/
		tab country, gen(countryd_)
		drop countryd_1 /*the first one stays out of the regression; */

		cls
		rdrobust `j' rdd_score if above_below_sd==`x', vce (nncluster loc_ID) covs(year_`x'* countryd_*) level(95)
		
		translate @Results "figure5`j'_`x'.txt", replace
		
}
}



local party_size 1 2 3

local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local party_size{
import delimited "figure5`j'_`x'.txt", delimiters("\t") clear

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)




split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}

capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23+data24+data25
capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23+data24
capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1



gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="Continuity"
gen party_size="`x'"
gen DV="`j'"


save "figure5`j'_`x'.dta", replace
}
}

****merge them
use "figure5nat_perc_1.dta", clear
save "FINAL_figure5.dta", replace

local party_size 1 2 3
			
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local party_size{
use "FINAL_figure5.dta", clear
merge m:m DV party_size sample using "figure5`j'_`x'.dta"
drop _merge
save "FINAL_figure5.dta", replace

}
}

**graph the results

						
use "FINAL_figure5.dta", clear
	
tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right
	

mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Small" r2="Medium" r3="Large")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		ytitle("Party Size") ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(cont_nat_perc, replace)						
						
						keep if DV=="nat_perc10"
						
mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc10", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 =" -" r2=" - " r3="  -")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(cont_nat_perc10, replace)
						
					 grc1leg cont_nat_perc.gph cont_nat_perc10.gph, cols(2) graphregion(color(white)) saving(cont_by_party_size, replace)
				 graph export "figure5.pdf", replace


				 
							*****Figure 6*****
							

local DV nat_perc nat_perc10
	

foreach j of local DV{
	use "data_torun_FINAL6.dta", clear
		***gen year dummies that are unique for each country
		tab nat_year, gen(yeardummy_)
		drop yeardummy_1 /*the first one stays out of the regression*/
		tab country, gen(countrydummy_)
		drop countrydummy_1 /*the first one stays out of the regression; */

		cls
rdrobust `j' rdd_score if gov_party==0, vce (nncluster loc_ID) covs(yeardu* countrydu*) level(95)
rdrobust `j' rdd_score if gov_party==1, vce (nncluster loc_ID) covs(yeardu* countrydu*) level(95)

		translate @Results "figure6`j'.txt", replace

}	
		
	local DV nat_perc nat_perc10

foreach j of local DV{
import delimited "figure6`j'.txt", delimiters("\t") clear

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)




split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}

capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data22+data23

capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data22
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2|_n==4
replace stat="N" if _n==1|_n==3

gen low=results6[2] if _n<3
gen up=results7[2]  if _n<3
replace low=results6[4] if _n>2
replace up=results7[4] if _n>2

gen NL=results2[1] if _n<3
gen NR=results3[1] if _n<3
replace NL=results2[3] if _n>2
replace NR=results3[3] if _n>2

gen coef2=results2[2] if _n<3
replace coef2=results2[4] if _n>2

keep if stat=="coeff"


gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

gen sample="gov" if _n==2
replace sample="nogov" if _n==1
gen DV="`j'"


save "figure6`j'.dta", replace
}


****merge them
use "figure6nat_perc.dta", clear
save "FINAL_figure6.dta", replace

		
local DV nat_perc nat_perc10

foreach j of local DV {
use "FINAL_figure6.dta", clear
merge m:m DV sample using "figure6`j'.dta"
drop _merge
save "FINAL_figure6.dta", replace

}


**Graph the effects

use "FINAL_figure6.dta", clear
		tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right

 mkmat coef low_regular95 up_regular95 if sample=="gov"&DV=="nat_perc", mat(Government_Party)
  mkmat coef low_regular95 up_regular95 if sample=="nogov"&DV=="nat_perc", mat(Opposition_Party)
 

 coefplot (matrix(Government_Party[,1]), ci((Government_Party[,2] Government_Party[,3])) ///
	mlabel(effective_number) mlabposition(12) mlabsize(tiny)) ///
		(matrix(Opposition_Party[,1]), ci((Opposition_Party[,2] Opposition_Party[,3])) ///
		mlabel(effective_number) mlabposition(12) mlabsize(tiny) msymbol(S)) ///
		, ///
		rename(r1 =".") xline(0) ///
		graphregion(color(white)) ylab(,nogrid) ysize(1.5) xsize(2) ///
		fxsize(100) title("Percent") saving(cont_gov_nat_perc, replace)
 
					keep if DV=="nat_perc10"
 mkmat coef low_regular95 up_regular95 if sample=="gov"&DV=="nat_perc10", mat(Government_Party)
  mkmat coef low_regular95 up_regular95 if sample=="nogov"&DV=="nat_perc10", mat(Opposition_Party)
 

 coefplot (matrix(Government_Party[,1]), ci((Government_Party[,2] Government_Party[,3])) ///
 		mlabel(effective_number) mlabposition(12) mlabsize(tiny)) ///
		(matrix(Opposition_Party[,1]), ci((Opposition_Party[,2] Opposition_Party[,3])) ///
		 	mlabel(effective_number) mlabposition(12) mlabsize(tiny) msymbol(S)) ///
		, ///
		rename(r1 =".") xline(0) ///
		graphregion(color(white)) ylab(,nogrid) ysize(1.5) xsize(2) ///
		fxsize(100) title("Percent adjusted") saving(cont_gov_nat_perc10, replace)	
		
  grc1leg cont_gov_nat_perc.gph cont_gov_nat_perc10.gph, cols(2)  graphregion(color(white)) saving(cont_gov_combined, replace)

  graph export "figure6.pdf", replace
 

								******Appendix*****
	
								******Figure A1****
								
	use "data_torun_FINAL6.dta", clear
	
local DV nat_perc nat_perc10 

foreach x of local DV{
forvalues i=3(2)7 {
		cls
	rdrandinf `x' rdd_score, level(.05) interfci(.05) wl(-`i') wr(`i')
		
		translate @Results "figureA1_`x'_`i'.txt", replace


}
}



***Bring in the txt results from thre regression
	local DV nat_perc nat_perc10

foreach x of local DV{
forvalues i=3(2)7 {
import delimited "figureA1_`x'_`i'.txt", delimiters("\t") clear

**keep confidence intervals first
keep if strpos(v1, "Eff. Number of obs")|strpos(v1, "Diff. in means")

split v1, p("Reps") gen(test)
drop test2
replace test1=subinstr(test1, "Eff. Number of obs|","",.)
replace test1=subinstr(test1, "Diff. in means|","",.)



split test1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}

gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16

keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="ci" if _n==3
replace stat="N" if _n==1

gen low=results2[3]
gen up=results3[3]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="`i'"
gen country="`x'"


save "figureA1`x'_`i'.dta", replace
}
}


****merge them
use "figureA1nat_perc_3.dta", clear
save "FINAL_figureA1.dta", replace

		
local country nat_perc nat_perc10

foreach x of local country{
forvalues i=3(2)7 {
use "FINAL_figureA1.dta", clear
merge m:m country sample using "figureA1`x'_`i'.dta"
drop _merge
save "FINAL_figureA1.dta", replace

}
}

***graph them


tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right



mkmat coef low_regular95 up_regular95 if sample=="3"&country=="nat_perc", mat(Bandwidth_3)
  mkmat coef low_regular95 up_regular95 if sample=="5"&country=="nat_perc", mat(Bandwidth_5)
  mkmat coef low_regular95 up_regular95 if sample=="7"&country=="nat_perc", mat(Bandwidth_7)

 coefplot (matrix(Bandwidth_3[,1]), ci((Bandwidth_3[,2] Bandwidth_3[,3]))) ///
		(matrix(Bandwidth_5[,1]), ci((Bandwidth_5[,2] Bandwidth_5[,3]))) ///
		(matrix(Bandwidth_7[,1]), ci((Bandwidth_7[,2] Bandwidth_7[,3]))), ///
		rename(r1 =".")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) ///
		graphregion(color(white)) ylab(,nogrid) ysize(1.5) xsize(2) ///
		xscale(range(-1 3)) xmtick(-1(.5)3) xlabel(-1(.5)3) ///
		fxsize(100) title("Percent") saving(fig1_rand_nat_perc, replace)
		
mkmat coef low_regular95 up_regular95 if sample=="3"&country=="nat_perc10", mat(Bandwidth_3)
  mkmat coef low_regular95 up_regular95 if sample=="5"&country=="nat_perc10", mat(Bandwidth_5)
  mkmat coef low_regular95 up_regular95 if sample=="7"&country=="nat_perc10", mat(Bandwidth_7)

 coefplot (matrix(Bandwidth_3[,1]), ci((Bandwidth_3[,2] Bandwidth_3[,3]))) ///
		(matrix(Bandwidth_5[,1]), ci((Bandwidth_5[,2] Bandwidth_5[,3]))) ///
		(matrix(Bandwidth_7[,1]), ci((Bandwidth_7[,2] Bandwidth_7[,3]))), ///
		rename(r1 =" .")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) ///
		graphregion(color(white)) ylab(,nogrid) ysize(1.5) xsize(2) ///
		xscale(range(-1 11)) xmtick(-1(2)11) xlabel(-1(2)11) ///
		fxsize(100) title("Percent adjusted") saving(fig1_rand_nat_perc10, replace)
		
		
		 grc1leg fig1_rand_nat_perc.gph fig1_rand_nat_perc10.gph, cols(2) graphregion(color(white)) saving(fig1_rand_combined, replace)

 graph export "figureA1.pdf", replace
 
										****Figure A2****
										
		
local country Austria Czechia France Germany Italy Portugal Romania Spain ///
				Belgium Bulgaria Denmark Finland Latvia Lithuania
				
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local country{
forvalues i=3(2)7 {
			cls
 			use "data_torun_FINAL6.dta", clear
		
rdrandinf `j' rdd_score if country=="`x'", level(.05) interfci(.05) wl(-`i') wr(`i')

translate @Results "figureA2`j'_`x'_`i'.txt", replace
}
}
}

local country Austria Czechia France Germany Italy Portugal Romania Spain ///
				Belgium Bulgaria Denmark Finland Latvia Lithuania
				
	local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local country{
forvalues i=3(2)7 {

import delimited "figureA2`j'_`x'_`i'.txt", delimiters("\t") clear
**keep confidence intervals first
keep if strpos(v1, "Eff. Number of obs")|strpos(v1, "Diff. in means")

split v1, p("Reps") gen(test)
drop test2
replace test1=subinstr(test1, "Eff. Number of obs|","",.)
replace test1=subinstr(test1, "Diff. in means|","",.)



split test1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}

gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16

keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="ci" if _n==3
replace stat="N" if _n==1

gen low=results2[3]
gen up=results3[3]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="`i'"
gen country="`x'"
gen DV="`j'"

save "FINAL_figureA2`j'_`x'_`i'.dta", replace

}
}
}

****merge them
use "FINAL_figureA2nat_perc_Austria_3.dta", clear
save "FINAL_figureA2.dta", replace

		
local country Austria Czechia France Germany Italy Portugal Romania Spain ///
				Belgium Bulgaria Denmark Finland Latvia Lithuania
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local country{
forvalues i=3(2)7 {
use "FINAL_figureA2.dta", clear
merge m:m DV country sample using "FINAL_figureA2`j'_`x'_`i'.dta"
drop _merge
save "FINAL_figureA2.dta", replace

}
}
}

***Graph them
use "FINAL_figureA2.dta", clear
		
		***keeep only a few countries
		keep if country=="Austria"|country=="Czechia"|country=="France"|country=="Germany"| ///
					country=="Italy"|country=="Portugal"|country=="Romania"|country=="Spain"
*declare dataset as matrix


gen sample2=real(sample)
sort DV country sample2
	
tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right


mkmat coef low_regular95 up_regular95 if sample=="3"&DV=="nat_perc", mat(Bandwidth_3)
  mkmat coef low_regular95 up_regular95 if sample=="5"&DV=="nat_perc", mat(Bandwidth_5)
  mkmat coef low_regular95 up_regular95 if sample=="7"&DV=="nat_perc", mat(Bandwidth_7)

 coefplot (matrix(Bandwidth_3[,1]), ci((Bandwidth_3[,2] Bandwidth_3[,3]))) ///
		(matrix(Bandwidth_5[,1]), ci((Bandwidth_5[,2] Bandwidth_5[,3]))) ///
		(matrix(Bandwidth_7[,1]), ci((Bandwidth_7[,2] Bandwidth_7[,3]))), ///
		rename(r1 ="Austria" r2="Czechia" r3="France" r4="Germany" r5="Italy" r6="Portugal" r7="Romania" r8="Spain")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(rand_nat_perc, replace)
		
mkmat coef low_regular95 up_regular95 if sample=="3"&DV=="nat_perc10", mat(Bandwidth_3)
  mkmat coef low_regular95 up_regular95 if sample=="5"&DV=="nat_perc10", mat(Bandwidth_5)
  mkmat coef low_regular95 up_regular95 if sample=="7"&DV=="nat_perc10", mat(Bandwidth_7)

 coefplot (matrix(Bandwidth_3[,1]), ci((Bandwidth_3[,2] Bandwidth_3[,3]))) ///
		(matrix(Bandwidth_5[,1]), ci((Bandwidth_5[,2] Bandwidth_5[,3]))) ///
		(matrix(Bandwidth_7[,1]), ci((Bandwidth_7[,2] Bandwidth_7[,3]))), ///
		rename(r1 ="Austria" r2="Czechia" r3="France" r4="Germany" r5="Italy" r6="Portugal" r7="Romania" r8="Spain")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(rand_nat_perc10, replace)
		
			 grc1leg rand_nat_perc.gph rand_nat_perc10.gph, cols(2) graphregion(color(white)) saving(rand_by_country, replace)
	
 graph export "figureA2.pdf", replace
 
 
											****Figure A3*****
											
											
		
	
local threshold -4 -3 -2 -1 1 2 3 4
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local threshold{
 			use "data_torun_FINAL6.dta", clear
			
		tab nat_year, gen(yeardummy_)
		drop yeardummy_1 /*the first one stays out of the regression*/
		tab country, gen(countrydummy_)
		drop countrydummy_1 /*the first one stays out of the regression*/
		cls
rdrobust `j' rdd_score if rdd_score*`x'>0, vce (nncluster loc_ID) c(`x') covs(yeardu* countrydu*) level(95)
		* 

translate @Results "figureA3`j'_`x'.txt", replace
}
}

			
			*******Bring in and clean the results


local threshold -4 -3 -2 -1 1 2 3 4
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local threshold{

import delimited "figureA3`j'_`x'.txt", delimiters("\t") clear

**keep confidence intervals first

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)




split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}


capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23+data24
capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1

gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="Continuity"
gen threshold="`x'"
gen DV="`j'"


save "figureA3`j'_`x'_cont.dta", replace

}
}


****merge them
use "figureA3nat_perc_2_cont.dta", clear
save "FINAL_figureA3_cont.dta", replace

		
local threshold -4 -3 -2 -1 1 2 3 4

			 
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local threshold{
use "FINAL_figureA3_cont.dta", clear
merge m:m DV threshold sample using "figureA3`j'_`x'_cont.dta"
drop _merge
save "FINAL_figureA3_cont.dta", replace

}
}
		
	*****Graph the results with continuity placebos	
	
	use "FINAL_figureA3_cont.dta", clear

	gen threshold2=real(threshold)
sort DV threshold2 sample

tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right

mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="-4" r2="-3" r3="-2" r4="-1" r5="1" r6="2" r7="3" r8="4") ///
					xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(cont_nat_perc, replace)						
						
mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc10", mat(Continuity)

keep if DV=="nat_perc10"
 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="-4" r2="-3" r3="-2" r4="-1" r5="1" r6="2" r7="3" r8="4") ///
					xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(cont_nat_perc10, replace)
						
					 grc1leg cont_nat_perc.gph cont_nat_perc10.gph, cols(2) graphregion(color(white)) saving(cont_by_country, replace)
				 graph export "figureA3.pdf", replace	
				 
				 
										****Figure A4****
										
	
local band 8 10 12 14 16
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local band{
 			use "data_torun_FINAL6.dta", clear
			
		tab nat_year, gen(yeardummy_)
		drop yeardummy_1 /*the first one stays out of the regression*/
		tab country, gen(countrydummy_)
		drop countrydummy_1 /*the first one stays out of the regression; */

		cls
rdrobust `j' rdd_score, vce (nncluster loc_ID) h(`x') covs(yeardu* countrydu*) level(95)


translate @Results "cont_figureA4`j'_`x'.txt", replace
}
}

			
			*******Bring in and clean the results


local band 8 10 12 14 16
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local band{

import delimited "cont_figureA4`j'_`x'.txt", delimiters("\t") clear

**keep confidence intervals first

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)




split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}


capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23+data24
capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1

gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="Continuity"
gen bandwidth="`x'"
gen DV="`j'"


save "FINAL_figureA4`j'_`x'_cont.dta", replace

}
}


****merge them
use "FINAL_figureA4nat_perc_8_cont.dta", clear
save "FINAL_figureA4_cont.dta", replace

		
local band 8 10 12 14 16

			 
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local band{
use "FINAL_figureA4_cont.dta", clear
merge m:m DV bandwidth sample using "FINAL_figureA4`j'_`x'_cont.dta"
drop _merge
save "FINAL_figureA4_cont.dta", replace

}
}

	*****Graph the results with continuity different bandwidths	
	
	use "FINAL_figureA4_cont.dta", clear

	gen bandwidth2=real(bandwidth)
sort DV bandwidth2 sample

tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right

mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="8" r2="10" r3="12" r4="14" r5="16") ///
					xline(0, lcolor(red) lwidth(thin)) xscale(range(-.25 2)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(cont_nat_perc, replace)						
						
						keep if DV=="nat_perc10"
mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc10", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="8" r2="10" r3="12" r4="14" r5="16") ///
					xline(0, lcolor(red) lwidth(thin)) xscale(range(-.25 8)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(cont_nat_perc10, replace)
						
					 grc1leg cont_nat_perc.gph cont_nat_perc10.gph, cols(2) graphregion(color(white)) saving(cont_by_country, replace)
				 graph export "figureA4.pdf", replace	

	
											*****Figure A5*****
											

local hole 1 2 3 4 5
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local hole{
 			use "data_torun_FINAL6.dta", clear

			
		tab nat_year, gen(yeardummy_)
		drop yeardummy_1 /*the first one stays out of the regression*/
		tab country, gen(countrydummy_)
		drop countrydummy_1 /*the first one stays out of the regression;*/

		cls
rdrobust `j' rdd_score if rdd_score<`x'*-0.1|rdd_score>`x'*0.1, vce (nncluster loc_ID) covs(yeardu* countrydu*) level(95)

translate @Results "figureA5`j'_`x'.txt", replace
}
}

			
			*******Bring in and clean the results


local hole 1 2 3 4 5
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local hole{

import delimited "figureA5`j'_`x'.txt", delimiters("\t") clear

**keep confidence intervals first

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)




split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}

capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23+data24+data25
capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23+data24
capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1

gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="Continuity"
gen hole="`x'"
gen DV="`j'"


save "figureA5`j'_`x'_cont.dta", replace

}
}


****merge them
use "figureA5nat_perc_1_cont.dta", clear
save "figureA5_cont.dta", replace

		
local hole 1 2 3 4 5

			 
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local hole{
use "figureA5_cont.dta", clear
merge m:m DV hole sample using "figureA5`j'_`x'_cont.dta"
drop _merge
save "figureA5_cont.dta", replace

}
}

				*****Graph results with donut hole****

	use "figureA5_cont.dta", clear

sort DV hole sample

tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right

mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 =".1" r2=".2" r3=".3" r4=".4" r5=".5") ///
					xline(0, lcolor(red) lwidth(thin))  xscale(range(-.25 2)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(cont_nat_perc, replace)						
						
						keep if DV=="nat_perc10"
mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc10", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 =".1" r2=".2" r3=".3" r4=".4" r5=".5") ///
					xline(0, lcolor(red) lwidth(thin)) xscale(range(-.5 7)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(cont_nat_perc10, replace)
						
					 grc1leg cont_nat_perc.gph cont_nat_perc10.gph, cols(2) graphregion(color(white)) saving(cont_by_country, replace)
				 graph export "figureA5.pdf", replace	
				 

											
								***Figure A6****
									
local country Austria Czechia France Germany Italy Portugal Romania Spain Belgium Bulgaria Denmark ///
			Finland Latvia Lithuania Luxembourg
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local country{
 			use "data_torun_FINAL6.dta", clear
			
		tab nat_year, gen(yeardummy_)
		drop yeardummy_1 /*the first one stays out of the regression*/
		tab country, gen(countrydummy_)
		drop countrydummy_1 /*the first one stays out of the regression; in the case of single country there's basically no dummy*/

		cls
rdrobust `j' rdd_score if country!="`x'", vce (nncluster loc_ID) covs(yeardu* countrydu*) level(95)


translate @Results "figureA6`j'_`x'.txt", replace
}
}

			
			*******Bring in and clean the results


local country Austria Czechia France Germany Italy Portugal Romania Spain Belgium Bulgaria Denmark ///
			Finland Latvia Lithuania Luxembourg
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local country{

import delimited "figureA6`j'_`x'.txt", delimiters("\t") clear


**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)




split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}

capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23+data24
capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1

gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="Continuity"
gen country="`x'"
gen DV="`j'"


save "figureA6`j'_`x'_cont.dta", replace

}
}


****merge them
use "figureA6nat_perc_Austria_cont.dta", clear
save "figureA6.dta", replace

		
local country Austria Belgium Bulgaria Czechia Denmark Finland France Germany ///
			Italy Latvia Lithuania Luxembourg Portugal Romania Spain
			 
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local country{
use "figureA6.dta", clear
merge m:m DV country sample using "figureA6`j'_`x'_cont.dta"
drop _merge
save "figureA6.dta", replace

}
}

**Graph the results

sort DV country sample

tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right

mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Austria" r2="Belgium" r3="Bulgaria" r4="Czechia" r5="Denmark" r6="Finland" r7="France" ///
			r8="Germany" r9="Italy" r10="Latvia" r11="Lithuania" r12="Luxembourg" r13="Portugal" r14="Romania" r15="Spain") ///	
			xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(cont_nat_perc, replace)						
						
						keep if DV=="nat_perc10"
mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc10", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Austria" r2="Belgium" r3="Bulgaria" r4="Czechia" r5="Denmark" r6="Finland" r7="France" ///
			r8="Germany" r9="Italy" r10="Latvia" r11="Lithuania" r12="Luxembourg" r13="Portugal" r14="Romania" r15="Spain") ///
			xline(0, lcolor(red) lwidth(thin)) xscale(range(-1 13)) xlabel(0 2 4 6 8 10 12) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(cont_nat_perc10, replace)
						
					 grc1leg cont_nat_perc.gph cont_nat_perc10.gph, cols(2) graphregion(color(white)) saving(cont_by_country, replace)
				 graph export "figureA6.pdf", replace


											*****Figure A7*****
											
	
local cycle 1 2 3
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local cycle{
 			use "data_torun_FINAL6.dta", clear

		***gen year dummies that are unique for each country
		tab nat_year if local_cycle3==`x', gen(year_`x')
		drop year_`x'1 /*the first one stays out of the regression*/
		tab country, gen(countryd_)
		drop countryd_1 /*the first one stays out of the regression; in the case of single country there's basically no dummy*/

		drop if rdd_score==0
		cls
		rdrobust `j' rdd_score if local_cycle3==`x', vce (nncluster loc_ID) covs(year_`x'* countryd_*) level(95)
		
		translate @Results "figureA7`j'_`x'.txt", replace

}
}


local cycle 1 2 3

local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local cycle{
import delimited "figureA7`j'_`x'.txt", delimiters("\t") clear

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)




split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}

capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1

gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="Continuity"
gen cycle="`x'"
gen DV="`j'"


save "figureA7`j'_`x'.dta", replace
}
}

****merge them
use "figureA7nat_perc_1.dta", clear
save "figureA7.dta", replace

local cycle 1 2 3
			
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local cycle{
use "figureA7.dta", clear
merge m:m DV cycle sample using "figureA7`j'_`x'.dta"
drop _merge
save "figureA7.dta", replace

}
}

		***Graph the results
	
tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right
	

mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="1" r2="2" r3="3")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(cont_nat_perc, replace)						
						
						keep if DV=="nat_perc10"
mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc10", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="1" r2="2" r3="3")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(cont_nat_perc10, replace)
						
					 grc1leg cont_nat_perc.gph cont_nat_perc10.gph, cols(2) graphregion(color(white)) saving(cont_by_country, replace)
				 graph export "figureA7.pdf", replace

				 
									****Figure A8****
									
		****first create the dataset on incumbency
use "data_torun_FINAL6.dta", clear

sort country loc_string party loc_year

gen maj_seats=.
replace maj_seats=0 if rdd_score<0
replace  maj_seats=1 if rdd_score>0

gen   incumbent=.
by country loc_string party, sort: replace incumbent=0 if maj_seats[_n-1]==0
by country loc_string party, sort: replace incumbent=1 if maj_seats[_n-1]==1

*gen a variable that notes the new sample: (1) above threshold and incumbent (2)all observations below threshold
*replace rdd_score=. if rdd_score>0&incumbent==0|rdd_score>0&incumbent==.

gen incumbency=0
replace incumbency=1 if incumbent==1&rdd_score>0|rdd_score<0

gen status=""
replace status="nonincumbency" if incumbency==0

tab nat_year, gen (year_dummy)
tab country, gen(country_dummy)


save "incumbency.dta", replace
		
				
local unit all nonincumbency
				
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local unit{
 			use "incumbency.dta", clear


		cls
		rdrobust `j' rdd_score if status!="`x'", vce (nncluster loc_ID) covs(registered year_dummy2-year_dummy23 country_dummy2-country_dummy15) level(95)
		
		translate @Results "figureA8`j'_`x'.txt", replace

}
}


local unit all nonincumbency
				
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local unit{
import delimited "figureA8`j'_`x'.txt", delimiters("\t") clear

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)



split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}


capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1

gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="Continuity"
gen unit="`x'"
gen DV="`j'"


save "figureA8`j'_`x'.dta", replace
}
}

****merge them
use "figureA8nat_perc_all.dta", clear
save "figureA8.dta", replace

		
local unit all nonincumbency
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local unit{
use "figureA8.dta", clear
merge m:m DV unit sample using "figureA8`j'_`x'.dta"
drop _merge
save "figureA8.dta", replace

}
}

*******Graph the results


sort DV unit sample

tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right

mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Full sample" r2="Long incumbency")  ///
		xline(0, lcolor(red) lwidth(thin)) xscale(range (-.5 3)) xlabel(-.5(.5)3) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(cont_nat_perc, replace)						
						
						keep if DV=="nat_perc10"
mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc10", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Full sample" r2="Long incumbency")  ///
		xline(0, lcolor(red) lwidth(thin)) xscale(range (-1 9)) xlabel(-1(1)9) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(cont_nat_perc10, replace)
						
					 grc1leg cont_nat_perc.gph cont_nat_perc10.gph, cols(2) graphregion(color(white)) ///
					 saving(denmark&finland, replace)
				 graph export "figureA8.pdf", replace
				 

											****Figure A9****
											
	
local unemp 0 1
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local unemp{
	use "data_torun_FINAL6.dta", clear

		keep if country=="Belgium"|country=="Denmark"|country=="Finland"|country=="Romania"
								*we only have unemployment data from these countries
	drop if country=="Romania"&nat_year<2012 /*we only got data from 2012 and 2016 for romania*/
		***gen year dummies that are unique for each country
		tab nat_year, gen(yeard_)
		drop yeard_1 /*the first one stays out of the regression*/
		tab country, gen(countryd_)
		drop countryd_1 /*the first one stays out of the regression*/

		cls
		rdrobust `j' rdd_score if high_unemp==`x', vce (nncluster loc_ID) covs(yeard_* countryd_*) level(95)
		
		translate @Results "figureA9`j'_`x'.txt", replace

}
}


local unemp 0 1

local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local unemp{
import delimited "figureA9`j'_`x'.txt", delimiters("\t") clear

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)




split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}


capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23+data24
capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19
			
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1

gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="Continuity"
gen unemp="`x'"
gen DV="`j'"


save "figureA9`j'_`x'.dta", replace
}
}

****merge them
use "figureA9nat_perc_0.dta", clear
save "figureA9.dta", replace

		
local unemp 0 1

local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local unemp{
use "figureA9.dta", clear
merge m:m DV unemp sample using "figureA9`j'_`x'.dta"
drop _merge
save "figureA9.dta", replace

}
}

		***Graph them
	
tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right
	

mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Low Unemployment" r2="High Unemployment")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(cont_nat_perc, replace)						
						
						keep if DV=="nat_perc10"
mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc10", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Low Unemployment" r2="High Unemployment")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(cont_nat_perc10, replace)
						
					 grc1leg cont_nat_perc.gph cont_nat_perc10.gph, cols(2) graphregion(color(white)) saving(cont_by_country, replace)
				 graph export "figureA9.pdf", replace


										****Figure A10****
										
use "eurobarometer_data.dta", clear
   
   keep if sample==1 /*only the countries included in our analysis*/
     

 
   			graph hbar (mean) avg_loc_country, over(country, sort(avg_loc_country) label(labsize(small))) blabel(bar, format(%2.0f)) ///
			  legend(off) graphregion(color(white)) yscale(r(0 100)) ylab(,nogrid nolabel) ytitle("")
			  
	   graph export "figureA10.pdf", replace


										***Figure A11***
   ****run the analyses

		
				
local local_politics 0 1
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local local_politics {

  use "data_torun_FINAL6.dta", clear
  
  merge m:m country using "eurobarometer_data2.dta"
  drop if _merge==2
		***gen year dummies that are unique for each country
		tab nat_year, gen(yeard_)
		drop yeard_1 /*the first one stays out of the regression*/
		tab country, gen(countryd_)
		drop countryd_1 /*the first one stays out of the regression*/

		cls
		rdrobust `j' rdd_score if dummy4==`x', vce (nncluster loc_ID) covs(yeard_* countryd_*) level(95)
		
		translate @Results "figureA11`j'_`x'.txt", replace

}
}


local local_politics 0 1
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local local_politics {

import delimited "figureA11`j'_`x'.txt", delimiters("\t") clear

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)




split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}


capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23+data24
capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19
			
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1

gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen local_politics="`x'"
gen DV="`j'"


save  "figureA11`j'_`x'.dta", replace
}
}
	
****Merge them

use "figureA11nat_perc_0.dta", clear
save "figureA11.dta", replace

local local_politics 0 1
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local local_politics {

use "figureA11.dta", clear
merge m:m DV local_politics using "figureA11`j'_`x'.dta"
drop _merge
save "figureA11.dta", replace

}
}
		
	***Graph them
	
tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right
	

mkmat coef low_regular95 up_regular95 if DV=="nat_perc", mat(Continuity)

 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Low Local Politics" r2="High Local Politics")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		xscale(range(-1 3)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(cont_nat_perc, replace)						
						
						keep if DV=="nat_perc10"
mkmat coef low_regular95 up_regular95 if DV=="nat_perc10", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Low Local Politics" r2="High Local Politics")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		xscale(range(-5 15)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(cont_nat_perc10, replace)
						
					 grc1leg cont_nat_perc.gph cont_nat_perc10.gph, cols(2) graphregion(color(white)) saving(eurob, replace)
				 graph export "figureA11.pdf", replace
		
		
										***Figure A12***
										
		
				
local local_politics 0 1
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local local_politics {

  use "data_torun_FINAL6.dta", clear
  
  merge m:m country nat_year using "eurobarometer_data_detailed.dta"
  drop if _merge==2
		***gen year dummies that are unique for each country
		tab nat_year, gen(yeard_)
		drop yeard_1 /*the first one stays out of the regression*/
		tab country, gen(countryd_)
		drop countryd_1 /*the first one stays out of the regression*/

		cls
		rdrobust `j' rdd_score if dummy5==`x', vce (nncluster loc_ID) covs(yeard_* countryd_*) level(95)
		translate @Results "figureA12`j'_`x'.txt", replace

}
}


local local_politics 0 1
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local local_politics {

import delimited "figureA12`j'_`x'.txt", delimiters("\t") clear

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)




split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}


capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23+data24
capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19
			
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1

gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen local_politics="`x'"
gen DV="`j'"


save  "figureA12`j'_`x'.dta", replace
}
}
	
****Merge them

use "figureA12nat_perc_0.dta", clear
save "figureA12.dta", replace

local local_politics 0 1
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local local_politics {

use "figureA12.dta", clear
merge m:m DV local_politics using "figureA12`j'_`x'.dta"
drop _merge
save "figureA12.dta", replace

}
}
		
	***Graph them
	
tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right
	

mkmat coef low_regular95 up_regular95 if DV=="nat_perc", mat(Continuity)

 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Low Local Politics" r2="High Local Politics")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		xscale(range(-1 3)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(cont_nat_perc, replace)						
						
						keep if DV=="nat_perc10"
mkmat coef low_regular95 up_regular95 if DV=="nat_perc10", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Low Local Politics" r2="High Local Politics")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		xscale(range(-5 15)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(cont_nat_perc10, replace)
						
					 grc1leg cont_nat_perc.gph cont_nat_perc10.gph, cols(2) graphregion(color(white)) saving(eurob, replace)
				 graph export "figureA12.pdf", replace
				 
				 							***TAble A1***
			
			**The results for all countries have been saved in the file "FINAL_figure4.dta"
			*In figure 4 of the paper we only graphed a few of them, but the results for all of the countries can be found in the document
			
			use "FINAL_figure4.dta", clear
			
				 
							****Appendix 8, Descriptive Statistics****
							

use "data_torun_FINAL6.dta", clear

		*gen the average number of localities per country year
		replace district=region if district==""
		replace district=prov if district==""
		
		by country nat_year district loc, sort: egen number_parties=count(party)
		by country nat_year district loc, sort: egen nat_perc_average=mean(nat_perc)
		
		by country nat_year, sort: egen number_observations=count(party)
				by country nat_year, sort: egen count_gov_party=count(party) if gov_party==1
		gsort country nat_year -count_gov_party
		by country nat_year, sort: replace count_gov_party=count_gov_party[_n-1] if count_gov_party==.
		recode count_gov_party (.=0)
		
		by country nat_year, sort: egen number_observations_c1=count(party) if local_cycle3==1
		gsort country nat_year -number_observations_c1
		by country nat_year, sort: replace number_observations_c1=number_observations_c1[_n-1] if number_observations_c1==.
		recode number_observations_c1 (.=0)
		
		by country nat_year, sort: egen number_observations_c2=count(party) if local_cycle3==2
		gsort country nat_year -number_observations_c2
		by country nat_year, sort: replace number_observations_c2=number_observations_c2[_n-1] if number_observations_c2==.
		recode number_observations_c2 (.=0)
		
		by country nat_year, sort: egen number_observations_c3=count(party) if local_cycle3==3
		gsort country nat_year -number_observations_c3
		by country nat_year, sort: replace number_observations_c3=number_observations_c3[_n-1] if number_observations_c3==.
		recode number_observations_c3 (.=0)	
		
		sort country nat_year district loc
drop if country==country[_n-1]&nat_year==nat_year[_n-1]&district==district[_n-1]&loc==loc[_n-1]

		by country nat_year, sort: egen parties_by_year=mean(number_parties)
		by country nat_year, sort: egen nat_perc_by_year=mean(nat_perc_average)

by country nat_year, sort: egen number_locs=count(loc)
drop if country==country[_n-1]&nat_year==nat_year[_n-1]
by country, sort: egen avg_locs=mean(number_locs)
by country, sort: egen avg_parties=mean(parties_by_year)
by country, sort: egen avg_observations=mean(number_observations)
by country, sort: egen avg_percent=mean(nat_perc_by_year)
by country, sort: egen n_avg_cycle1=mean(number_observations_c1)
by country, sort: egen n_avg_cycle2=mean(number_observations_c2)
by country, sort: egen n_avg_cycle3=mean(number_observations_c3)
by country, sort: egen n_avg_gov_party=mean(count_gov_party)


drop if country==country[_n-1]
keep country avg_* n_avg_*
gen avg_cycle1=n_avg_cycle1/avg_observations*100
gen avg_cycle2=n_avg_cycle2/avg_observations*100
gen avg_cycle3=n_avg_cycle3/avg_observations*100
gen avg_gov_party=n_avg_gov_party/avg_observations*100

drop avg_nat_perc
drop n_avg*

 save "descriptive_stats.dta", replace
				 
						****Appendix 9***
						
 local country Austria Czechia France Germany Italy Portugal Romania Spain Belgium Bulgaria Denmark ///
			Finland Latvia Lithuania Luxembourg
			
foreach x of local country{
 			use "data_torun_FINAL6.dta", clear
			
			hist rdd_score if country=="`x'", color(gray) graphregion(color(white)) ///
			title("`x'") saving(hist_`x', replace)
			
			}
 
		grc1leg hist_Austria.gph hist_Belgium.gph hist_Bulgaria.gph hist_Czechia.gph hist_Denmark.gph ///
		hist_Finland.gph hist_France.gph hist_Germany.gph hist_Italy.gph hist_Latvia.gph hist_Lithuania.gph ///
		hist_Luxembourg.gph hist_Portugal.gph hist_Romania.gph hist_Spain.gph, cols(5) graphregion(color(white)) saving(cont_by_country, replace)
				 graph export "histograms.pdf", replace
				 
				


							
				 
						****Figure A13****
			
				
local unit rdd_score coalition_rdd_score
				
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local unit{
 			use "denmark&finland_coalitions2.dta", clear


		cls
		rdrobust `j' `x', vce (nncluster loc_ID) covs(registered year_dummy2-year_dummy4 country_dummy) level(95)
		
		translate @Results "figureA13`j'_`x'.txt", replace

}
}


local unit rdd_score coalition_rdd_score
				
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local unit{
import delimited "figureA13`j'_`x'.txt", delimiters("\t") clear

**keep confidence intervals first
keep if strpos(v1, "Conventional")|strpos(v1, "Eff. Number of obs |")

replace v1=subinstr(v1, "Eff. Number of obs |","",.)
replace v1=subinstr(v1, "Conventional |","",.)
replace v1=subinstr(v1, "VCE method    =  NNcluster","",.)



split v1, p(" ") gen(data)

keep data*

foreach v of varlist _all{
replace `v'="|"+`v' if `v'!=""
}


capture  gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22+data23
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21+data21+data22
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20+data21
			
capture gen results=data1+data2+data3+data4+data5+data6+data7+data8+data9+data10+data11+data12+data13+data14+data15+data16 ///
			+data17+data18+data19+data20
			
keep results*

split results, p("|")

gen stat="coeff" if _n==2
replace stat="N" if _n==1

gen low=results6[2]
gen up=results7[2]
gen NL=results2[1]
gen NR=results3[1]
gen coef2=results2[2]



gen low_regular95=real(low)
gen up_regular95=real(up) 
gen eff_N_left=real(NL)
gen eff_N_right=real(NR)
gen coeff=real(coef2)


keep low_-coeff

keep in 1

gen sample="Continuity"
gen unit="`x'"
gen DV="`j'"


save "figureA13`j'_`x'.dta", replace
}
}

****merge them
use "figureA13nat_perc_rdd_score.dta", clear
save "figureA13.dta", replace

		
local unit rdd_score coalition_rdd_score
local DV nat_perc nat_perc10 

foreach j of local DV {
foreach x of local unit{
use "figureA13.dta", clear
merge m:m DV unit sample using "figureA13`j'_`x'.dta"
drop _merge
save "figureA13.dta", replace

}
}

*******Graph the results


gsort DV -unit sample

tostring eff_N_left, gen(s_eff_N_left)
tostring eff_N_right, gen(s_eff_N_right)

gen effective_number="N(L)="+s_eff_N_left+"      "+"N(R)="+s_eff_N_right

mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Individual party" r2="Coalition")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent") saving(cont_nat_perc, replace)						
						
						keep if DV=="nat_perc10"
mkmat coef low_regular95 up_regular95 if sample=="Continuity"&DV=="nat_perc10", mat(Continuity)


 coefplot (matrix(Continuity[,1]), ci((Continuity[,2] Continuity[,3]))), ///
		rename(r1 ="Individual party" r2="Coalition")  ///
		xline(0, lcolor(red) lwidth(thin)) ///
		mlabel(effective_number) mlabposition(15) mlabsize(tiny) mlabgap(0) msize(small) mcolor(black) msymbol(S) ///
		graphregion(color(white)) ylab(,nogrid) title("Percent adjusted") saving(cont_nat_perc10, replace)
						
					 grc1leg cont_nat_perc.gph cont_nat_perc10.gph, cols(2) graphregion(color(white)) ///
					 saving(denmark&finland, replace)
				 graph export "figureA13.pdf", replace
				 
				 
									****Table A2****
use "cost_of_ruling_dataset.dta", clear					

rdrobust vote_perc lag_rdd_score, vce(cluster locality3) 

*Method	Coef.	Std. Err.	z	P>z	[95% Conf.	Interval]
						
*Conventional	1.6093	.32321	4.9791	0.000	.975832	2.24281

				 
									****Table A3****
*Education spending data from Denmark
use "ed_spending_denmark2.dta", clear			
		reg nat_perc stand_ed_year i.year i.party_nr  if loc_control==1 

*stand_ed_year |   2.503216    1.72571     1.45   0.160    -1.066688    6.073119

**Education spending data from Italy
use "ed_spending_italy2.dta", clear
	reg nat_perc stand_ed_year i.year i.party_nr  if loc_control==1 
								
 *stand_ed_year |   3.654879   1.594374     2.29   0.033     .3290737    6.980684
 
  **Education spending data from Romania
use "ed_spending_romania2.dta", clear
	reg nat_perc i.year i.party_nr stand_ed_year if loc_control==1 

 *stand_ed_year |   2.474024   1.140297     2.17   0.031     .2299701    4.718079
 
									*****Figure A14****


use "V-Dem-CD-v11.1.dta", clear

keep country_name year v2xel_locelec

keep if country=="Belgium"|country=="Bulgaria"|country=="Croatia"|country=="Czech Republic"|country=="Denmark"| ///
		country=="Estonia"|country=="Finland"|country=="France"|country=="Germany"|country=="Greece" ///
		|country=="Hungary"|country=="Ireland"|country=="Italy"|country=="Latvia"|country=="Lithuania"| ///
		country=="Luxembourg"|country=="Malta"|country=="Netherlands"|country=="Poland"|country=="Portugal"|country=="Romania"| ///
		country=="Slovakia"|country=="Slovenia"|country=="Spain"|country=="Sweden"|country=="United Kingdom"| ///
		country=="Cyprus"|country=="Austria"
		
	drop if v2xel_locelec==.	
	
	*gen a dummy for the 2004 and later expansion
	gen new_europe=.
	replace new_europe=1 if country=="Bulgaria"|country=="Croatia"|country=="Czech Republic"|country=="Estonia"| ///
			country=="Hungary"|country=="Latvia"|country=="Lithuania"|country=="Poland"|country=="Romania"| ///
		country=="Slovakia"|country=="Slovenia"|country=="Cyprus"|country=="Malta"
		recode new_europe (.=0)
		
		****gen average by mean
	by year, sort: egen vdem_all=mean(v2xel_locelec)
	by year, sort: egen vdem_new_europe=mean(v2xel_locelec) if new_europe==1
	gsort year -vdem_new_europe
	by year, sort: replace vdem_new_europe=vdem_new_europe[_n-1] if vdem_new_europe==.
	
	by year, sort: egen vdem_old_europe=mean(v2xel_locelec) if new_europe==0
	gsort year -vdem_old_europe
	by year, sort: replace vdem_old_europe=vdem_old_europe[_n-1] if vdem_old_europe==.
	
		*gen average by decade since 1950
		gen decade=.
		replace decade=1950 if year>1950&year<=1960
		replace decade=1960 if year>1960&year<=1970
		replace decade=1970 if year>1970&year<=1980
		replace decade=1980 if year>1980&year<=1990
		replace decade=1990 if year>1990&year<=2000
		replace decade=2000 if year>2000&year<=2010
		replace decade=2010 if year>2010&year<=2020

			by decade, sort: egen vdem_all2=mean(v2xel_locelec)
	by decade, sort: egen vdem_new_europe2=mean(v2xel_locelec) if new_europe==1
	gsort decade -vdem_new_europe2
	by decade, sort: replace vdem_new_europe2=vdem_new_europe2[_n-1] if vdem_new_europe2==.
	
	by decade, sort: egen vdem_old_europe2=mean(v2xel_locelec) if new_europe==0
	gsort decade -vdem_old_europe
	by decade, sort: replace vdem_old_europe2=vdem_old_europe2[_n-1] if vdem_old_europe2==.
	
	sort year
	drop if year==year[_n-1]
	
	by decade, sort: gen decade_nr=_n

	rename decade Decade
	
	twoway (scatter vdem_all2 Decade, msize(tiny)) (scatter vdem_old_europe2 Decade, msize(tiny)) (scatter vdem_new_europe2 Decade, msize(tiny)) ///
			(line vdem_all2 Decade, msize(tiny)) (line vdem_old_europe2 Decade, msize(tiny)) (line vdem_new_europe2 Decade, msize(tiny)), ///
			legend(order(4 "EU 28" 5 "EU 15" 6 "New members") size(small) col(3)) ///
		xlabel(1950 "1950s" 1960 "1960s" 1970 "1970s" 1980 "1980s" 1990 "1990s" 2000 "2000s" 2010 "2010s") ///
		graphregion(color(white)) 

	graph export "figureA14.pdf", replace

	
